﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class controls_usrCarDriverDetails : System.Web.UI.UserControl
{
    protected Int64 lngDriverId;
    protected string strDriverNo;
    protected string strMaritalStatus;
    protected DateTime dtDOB;
    protected char chrGender;
    protected string strOccupation;
    protected string strJobNature;
    protected byte byteYearOfDriving;
    protected string strValidationGroup;

    protected bool bEnabled = true;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            usrDOB.StartYear = CE.Global.General.GetUTCDateTime().Year - 60;
            usrDOB.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;

            ddlYersOfDriving.Attributes.Add("onblur", "ShowValidationEffect('" + ddlYersOfDriving.ClientID + "','" + rfvDrivingYearSg.ClientID + "');");
        }
    }

    public void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        ddlGender.ChangeValidationEffectServerSide(strValidationGroup);
        ddlOccupation.ChangeValidationEffectServerSide(strValidationGroup);
        ddlJobNature.ChangeValidationEffectServerSide(strValidationGroup);
        ddlMaritalStatus.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOB.ChangeValidationEffectServerSide(strValidationGroup);

        if (rfvDrivingYearSg.Enabled && rfvDrivingYearSg.ValidationGroup == strValidationGroup)
        {
            rfvDrivingYearSg.Validate();
            if (rfvDrivingYearSg.IsValid == false)
            {
                ddlYersOfDriving.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlYersOfDriving.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlYersOfDriving.ControlStyle.CssClass = "";
        }
    }

    public bool IsEnabled
    {
        get { return bEnabled; }
        set
        {
            bEnabled = value;
            SetEnabled();
        }
    }

    public string ValidationGroup
    {
        get { return strValidationGroup; }
        set { strValidationGroup = value; }
    }

    public string DriverNo
    {
        get { return strDriverNo; }
        set { strDriverNo = value; }
    }

    public Int64 DriverId
    {
        get { return lngDriverId; }
        set { lngDriverId = value; }
    }

    public DateTime DOB
    {
        get { return dtDOB; }
        set { dtDOB = value; }
    }

    public char Gender
    {
        get { return chrGender; }
        set { chrGender = value; }
    }

    public string MaritalStatus
    {
        get { return strMaritalStatus; }
        set { strMaritalStatus = value; }
    }

    public string Occupation
    {
        get { return strOccupation; }
        set { strOccupation = value; }
    }

    public string JobNature
    {
        get { return strJobNature; }
        set { strJobNature = value; }
    }

    public byte YearsOfDriving
    {
        get { return byteYearOfDriving; }
        set { byteYearOfDriving = value; }
    }

    public void SetEnabled()
    {
        ddlGender.IsEnabled = bEnabled;
        ddlOccupation.IsEnabled = bEnabled;
        ddlJobNature.IsEnabled = bEnabled;
        ddlYersOfDriving.Enabled = bEnabled;
        ddlMaritalStatus.IsEnabled = bEnabled;
        usrDOB.IsEnabled = bEnabled;
        rfvDrivingYearSg.Enabled = bEnabled;
    }

    public void IsEnableValidation(bool bValue)
    {
        usrDOB.IsEnableValidation(bValue);
        ddlGender.IsEnableValidation(bValue);
        ddlOccupation.IsEnableValidation(bValue);
        ddlJobNature.IsEnableValidation(bValue);
        rfvDrivingYearSg.Enabled = bValue;
        ddlMaritalStatus.IsEnableValidation(bValue);
    }

    protected override void OnPreRender(EventArgs e)
    {
        SetEnabled();

        

        if (strDriverNo != null)
        {
            lblDriverNo.Text = "Driver " + strDriverNo;
        }

        if (strValidationGroup != null)
        {
            usrDOB.ValidationGroup = strValidationGroup;
            ddlGender.ValidationGroup = strValidationGroup;
            ddlMaritalStatus.ValidationGroup = strValidationGroup;
            ddlOccupation.ValidationGroup = strValidationGroup;
            ddlJobNature.ValidationGroup = strValidationGroup;
            rfvDrivingYearSg.ValidationGroup = strValidationGroup;
        }

        if (lngDriverId != 0)
        {
            lblDriverId.Text = lngDriverId.ToString();
        }

        if (chrGender.ToString() != string.Empty)
        {
            if (chrGender == '0')
            {
                ddlGender.Gender = "Select";
            }
            else
            {
                ddlGender.Gender = chrGender.ToString();
            }
        }

        if (strMaritalStatus != null)
        {
            ddlMaritalStatus.MaritalStatus = strMaritalStatus;
        }

        if (strOccupation != null)
        {
            ddlOccupation.Occupation = strOccupation;
        }

        if (strOccupation != null)
        {
            ddlJobNature.JobNature = strJobNature;
        }

        if (byteYearOfDriving != 0)
        {
            ddlYersOfDriving.Text = byteYearOfDriving.ToString();
        }

        if (dtDOB != null)
        {
            //dtDOB = CE.Global.General.GetUTCDateTime().Date;
            usrDOB.Day = dtDOB.Day;
            usrDOB.Month = dtDOB.Month;
            usrDOB.Year = dtDOB.Year;
        }
    }

    public void SetProperty()
    {
        if (this.Page.IsValid)
        {
            lngDriverId = Convert.ToInt64(lblDriverId.Text == string.Empty ? "0" : lblDriverId.Text);
            dtDOB = usrDOB.GetDate();
            chrGender = Convert.ToChar(ddlGender.GetGender());
            strMaritalStatus = ddlMaritalStatus.GetMaritalStatus();
            strOccupation = ddlOccupation.GetOccupation();
            strJobNature = ddlJobNature.GetJobNature();
            byteYearOfDriving = Convert.ToByte(ddlYersOfDriving.SelectedValue.ToString());
        }

    }

    public void ClearProperty()
    {
        lngDriverId = 0;
        dtDOB = CE.Global.General.GetUTCDateTime().Date;
        chrGender = '0';
        strMaritalStatus = "";
        strOccupation = "";
        strJobNature = "";
        byteYearOfDriving = 0;
    }

    public void ClearValues()
    {
        usrDOB.Day = -1;
        usrDOB.Month = -1;
        usrDOB.Year = -1;

        ddlGender.Gender = "Select";
        ddlMaritalStatus.MaritalStatus = "-1";
        ddlJobNature.JobNature = "-1";
        ddlYersOfDriving.Text = "-1";

        //ClearProperty();
    }

}
